# -*- coding: utf-8 -*-
from venv1.Page.inqueryPage import inqueryPage
from selenium.webdriver.support.ui import Select
from xlutils.copy import copy
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.action_chains import ActionChains
import time
from venv1.Public.xlsx_utils import XlsxUtils
import xlrd
class inquery():
    def __init__(self,driver):
        self.driver=driver
        self.inqueryPage=inqueryPage(self.driver)
    def Assign_To(self,PolicyNo):
        window = self.driver.window_handles
        self.driver.switch_to.window(window[-1])

        time.sleep(1)
        CurPolicyMan = self.inqueryPage.PolicyMan().text
        print(CurPolicyMan)

        time.sleep(3)

        self.inqueryPage.btnIntegratedquery().click()
        time.sleep(1)
        self.inqueryPage.inpPolicyNo().clear()
        time.sleep(1)
        self.inqueryPage.inpPolicyNo().send_keys(PolicyNo)
        time.sleep(1)
        self.inqueryPage.btnQuery().click()
        time.sleep(4)
        self.inqueryPage.btnAssign().click()
        time.sleep(1)
        window1 = self.driver.window_handles
        self.driver.switch_to.window(window1[-1])
        time.sleep(1)
        PrePoicyMan=self.inqueryPage.inpPolicyMan().get_attribute('value')
        if PrePoicyMan!=CurPolicyMan:
            print("当前处理人！=指派人员")
            self.inqueryPage.inpAssignTo().click()
            time.sleep(1)
            self.inqueryPage.inpAssignTo().send_keys(CurPolicyMan)
            time.sleep(1)
            # self.driver.find_element_by_xpath("//span[text()='tracy.wang']").click()
            ActionChains(self.driver).key_down(Keys.DOWN).key_up(Keys.DOWN).key_down(Keys.ENTER).key_up(Keys.ENTER).perform()
            time.sleep(1)
            self.inqueryPage.btnComfire().click()
            time.sleep(1)
            self.inqueryPage.btnSumbit().click()
            time.sleep(1)
        else:
            print('当前处理人=指派人员')
            self.inqueryPage.btnCancel().click()
            time.sleep(1)
    def UWdecision(self,PolicyNo,row ):
        window1 = self.driver.window_handles
        self.driver.switch_to.window(window1[-1])
        time.sleep(1)

        self.inqueryPage.btnIntegratedquery().click()
        time.sleep(1)
        self.inqueryPage.inpPolicyNo().send_keys(PolicyNo)
        time.sleep(1)
        self.inqueryPage.btnQuery().click()
        time.sleep(1)
        uwdecision=self.inqueryPage.inpUWdecision().text
        time.sleep(1)
        print(self.inqueryPage.inpUWdecision().text)
        self.inqueryPage.btnTarget().click()
        time.sleep(1)

        window2 = self.driver.window_handles
        self.driver.switch_to.window(window2[-1])
        time.sleep(1)
        ActionChains(self.driver).key_down(Keys.CONTROL).send_keys('W').key_up(Keys.CONTROL).perform()
        time.sleep(1)
        Premium=self.inqueryPage.inpPremium().text
        time.sleep(1)
        print(Premium)


        xlutil = XlsxUtils()
        filename = r'..\TestData\outputdata.xlsx'
        xlutil.set_sheet_value(filename=filename, sheetname='Sheet1', row=row, col=6, value=uwdecision)
        xlutil.set_sheet_value(filename=filename, sheetname='Sheet1', row=row, col=7, value=Premium)
        self.driver.close()
        time.sleep(2)
        window4 = self.driver.window_handles
        self.driver.switch_to.window(window4[-1])
        time.sleep(2)







